package com.oauth.google.client.ui.gmail;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DeckPanel;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.oauth.google.client.rpc.gmail.GMailRemoteService;
import com.oauth.google.client.rpc.gmail.GMailRemoteServiceAsync;
import com.oauth.google.client.ui.GmailResources;

public class GoogleMailPanel extends Composite {

	protected final GMailRemoteServiceAsync googleService = GWT.create(GMailRemoteService.class);

	private static GoogleMailPanelUiBinder uiBinder = GWT.create(GoogleMailPanelUiBinder.class);

	interface GoogleMailPanelUiBinder extends UiBinder<FlowPanel, GoogleMailPanel> {
	}

	@UiField
	HorizontalPanel staticPanel;

	@UiField
	DeckPanel deckPanel;

	@UiField
	Anchor viewAllLink;

	@UiField
	HomePanel homePanel;

	@UiField
	Image logo;

	public GoogleMailPanel() {
		initWidget(uiBinder.createAndBindUi(this));
		logo.setResource(GmailResources.INSTANCE.image());
		staticPanel.setCellHorizontalAlignment(logo, VerticalPanel.ALIGN_LEFT);
		staticPanel.setCellHorizontalAlignment(viewAllLink, VerticalPanel.ALIGN_RIGHT);

	}

	public void init() {
		deckPanel.add(new HTML("This is under development"));
		deckPanel.showWidget(2);
		/*
		 * String queryString = Window.Location.getQueryString();
		 * HttpQueryString mailQueryString = new HttpQueryString(queryString);
		 * 
		 * googleService.getGoogleMail(mailQueryString, new
		 * OAuthAsnyCallBack<GoogleMailModel>() {
		 * 
		 * public void onSuccess(GoogleMailModel pModel) {
		 * 
		 * if (pModel != null) { if (pModel.isLoginView()) {
		 * deckPanel.showWidget(1); } else { deckPanel.showWidget(2); } } } });
		 */}

	@UiHandler("viewAllLink")
	public void onClick(ClickEvent pEvent) {
		Window.open("http://mail.google.com", "GMail", null);
	}
}